<?php


class Form_Register extends Zend_Form {

   public function __construct($options = null) {
      parent::__construct($options);
      
      
      $view = Zend_Layout::getMvcInstance()->getView(); 
      
      $countryModel =  new Model_Country();
      $countries = $countryModel->getCountryList();
      $clist = new Zend_Form_Element_Select('country');
      $clist->setRequired(true)
                 ->setOrder(7)
                 ->setLabel($view->translate->_('Country'))
                 ->setMultiOptions($countries)
      ; 
      /*->addDecorators(array(
                     array('Label'),
                     //array('HtmlTag', array('tag' => 'td'))*/
      //pr($countries);
      
      
      
      $this->setName('register');
      $fields = array(
         'username' => new Zend_Form_Element_Text('username', array('label' => $view->translate->_('Username'), 'required' => true)),
         'password' => new Zend_Form_Element_Password('password', array('label' => $view->translate->_('Password'), 'required' => true)),
         'password2' => new Zend_Form_Element_Password('password2', array('label' => $view->translate->_('RetypePassword'), 'required' => true)),
         'firstname' => new Zend_Form_Element_Text('firstname', array('label' => $view->translate->_('FirstName'), 'required' => true)),
         'lastname' => new Zend_Form_Element_Text('lastname', array('label' => $view->translate->_('LastName'), 'required' => true)),
         'email' => new Zend_Form_Element_Text('email', array('label' => $view->translate->_('Email'), 'required' => true)),
         'address' => new Zend_Form_Element_Text('address', array('label' => $view->translate->_('Address'), 'required' => true/*, 'cols' => 50, 'rows' => 15*/)),
         'city' => new Zend_Form_Element_Text('city', array('label' => $view->translate->_('City'), 'required' => true)),
         'zip' => new Zend_Form_Element_Text('zip', array('label' => $view->translate->_('Zip'), 'required' => true)),
         'state' => new Zend_Form_Element_Text('state', array('label' => $view->translate->_('State'))),
         'country' => $clist,
         'captcha' => new Zend_Form_Element_Captcha('captcha', array(
            'label' => $view->translate->_('Verification'),
            'captcha' => 'Image',
            'captchaOptions' => array(
               'wordLen' => 6,
               'timeout' => 300,
               'font' => './media/fonts/arial.ttf',
               'imgurl' => Zend_Controller_Front::getInstance()->getBaseUrl().'/images/captcha',
            ),
         )),
         'submit' => new Zend_Form_Element_Submit('login', array('label' => $view->translate->_('Register')))
      );
      
      $token = Zend_Controller_Front::getInstance()->getRequest()->getPost('password');      
      $fields['password2']->addValidator(new Zend_Validate_Identical(trim($token)))
                          ->addValidator(new Zend_Validate_StringLength(6, 30))
                          ->addFilter(new Zend_Filter_StringTrim())
                          ->isRequired();
                          
      $username = Zend_Controller_Front::getInstance()->getRequest()->getPost('username');
      $fields['username']->addValidator(new App_Validate_Unique('users', 'username'))
                         ->addValidator(new Zend_Validate_StringLength(6, 30))
                         ->addFilter(new Zend_Filter_StringTrim())                         
                         ->isRequired();
      
      $this->addElements($fields);
      $this->setMethod('post');
      $this->setAction(Zend_Controller_Front::getInstance()->getBaseUrl(). '/pages/register');

   }



}